using System.Collections.Generic;
using System.Reflection;
using WineCellar.Core.Interfaces;
using WineCellar.Core.PropertyParsers;
using WineCellar.Core.QueryObject;

namespace WineCellar.Core.QueryObject
{
    public class SearchObject : ISearchObject
    {
        /// <summary>
        /// Property returns a list of search parameters.
        /// </summary>
        /// <returns></returns>
        public List<ISearchParameter> GetParameters()
        {
            var parameters = new List<ISearchParameter>();

            PropertyInfo[] properties = GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public);
            foreach (PropertyInfo property in properties)
            {
                foreach (SearchAttribute search in property.GetCustomAttributes(typeof(SearchAttribute), false))
                {
                    search.Value = property.GetValue(this, null);

                    if (PropertyHelper.IsEmpty(search.Value))
                        continue;
                    parameters.Add(search);
                }
            }

            return parameters;
        }
    }
}